$(document).ready(function(){
 //加载option list

	//查询条件
	var queryParams = function () { 
       	var temp = { 
			account : $("#account").val(),
			email   :$("#email").val()
		};
		return temp;
	 };
	//搜索
	$("#searchBtn").click(function () {  
	    $('#listTable').bootstrapTable('refreshOptions',{pageNumber:1});
	});
	//列表
	window.operateEvents = {
   		'click #edtiButton': function (e, value, row, index) {//编辑
      		//直接从row中获取数据  然后赋值
      		$("#toPlan").modal("show");
	  		//ajax 提交完清空数据
	  		//$("#inputForm")[0].reset()
      }  		  
    };
			 
	$('#listTable').bootstrapTable({
        url: 'http://192.168.50.16:8080/rms/user/list',
		type : "post", //传值方式 
        toolbar: '#tableToolbar',
        pagination: true, //是否显示分页（*）
        sortable: true, //是否启用排序
		cache: true,
		dataType:"json",
		//contentType:'application/json', 
        sortName: "account", //默认排序字段
        sortOrder: "asc", //排序方式
        clickToSelect: true, //是否启用点击选中行
        uniqueId: "id", //每一行的唯一标识，一般为主键列
        showColumns:false,
        minimumCountColumns:2,
        queryParams: function (params){ return $.extend(params,queryParams()); },
        onLoadSuccess: function(data){if(data.total<1)$('#listTable').bootstrapTable("removeAll");},
        columns: [ 
		{
            title: 'id',
            field: 'id'
        }, {
            title: '用户名',
            field: 'account'
        }, 
		{
            title: '姓名', 
            field: 'username'
        }, {
            title: '用户类型',
            field: 'type',
			formatter:function(value,row,index){
				var type=row.type;
				if(type == "1"){
					return "管理员";
				}else{
					return "普通用户";
				}
			}
			
        },{
            title: '手机号',
            field: 'phone_num'
        }, 
		{
            title: '邮箱',
            field: 'email'
        }, 
		{
            title: '状态', 
            field: 'isTrue',
			formatter:function(value,row,index){
				var isTrue=row.isTrue;
				if(isTrue == "0"){
					return "停用";
				}else{
					return "启用";
				}
			}
        }, 

		{
            title: '角色名称',
            field: 'roleNames',
			formatter:function(value,row,index){
				var roleNames=row.roleNames;
				if(roleNames.length <= 10){
					return roleNames;
				}else{
					return "<span title="+roleNames+">"+roleNames.substring(0,10)+"...</span>";
				}
			}
			
        },{
            title: '操作',
            events: operateEvents,
            formatter: operateFormatter
        }	]
	});
			
	//隐藏列
    $('#listTable').bootstrapTable('hideColumn', 'id');
    
	//添加事件
	$("#addModel").click(function () {
       $("#toPlan").modal("show");
      });
	});
	//操作按钮内容	
	function operateFormatter(value, row, index) {
		return [
				'<div class="btn-group">',		      
					'<button class="btn btn-info btn-xs" name="edtiButton" id="edtiButton" type="button"><i class="fa fa-pencil-square-o"></i>&nbsp;&nbsp;编辑</button>',
		        '</div>'
		].join('');
    }
		